//
//  Response+JSONDecode.swift
//  grid-ios-app
//
//  Created by yanlu on 2024/5/16.
//

import Moya

extension Moya.Response {

    /// 使用IkigaJSONDecoder把JSON序列化成Model
    ///
    /// - Parameter type: 自定义Model的Type
    /// - Returns: 实例化的Model
    /// - Throws: 序列化错误
    public func decodeJSON<T>(from type: T.Type) throws -> T where T: Decodable {
        do {
            return try JSONDecoder().decode(type, from: data)
        } catch {
            throw error
        }
    }
}
